package com.hod.reservgrid.client.model;

import java.util.Date;
import com.google.gwt.core.client.GWT;
import com.google.gwt.gears.client.database.DatabaseException;

public class LodgingRecordset {
	
	public static boolean existsLodgingForClient(String idClient){
		GearsDataStore ds = (GearsDataStore) GWT.create(Lodging.class);
		try {
			GearsQuery q = ds.getNamedQuery(Lodging.FIND_VALID_LODGING_BY_IDCLIENT);
			q.setString(0, idClient);
			Lodging[] data = (Lodging[]) q.execute();
			return data.length>0;			
		} catch (DatabaseException e) {			
			// TODO Auto-generated catch block
			return false;
		}
		
	}
	
	
	public static Lodging getLodging(Integer idLodging) {
		// TODO Auto-generated method stub
		try {
			GearsDataStore ds = (GearsDataStore) GWT.create(Lodging.class);
			Lodging o = (Lodging) ds.findById(idLodging);
			return o;
		} catch (DatabaseException e) {
			// TODO Auto-generated catch block
			return null;
		} 
	}
	
	public static Client existsLodgingforRoom(Integer idRoom,Date date){
		GearsDataStore ds = (GearsDataStore) GWT.create(Client.class);
		try {
			GearsQuery q = ds.getNamedQuery(Client.EXISTS_LODGING_FOR_ROOM);
			q.setInteger(0, idRoom);
			q.setDate(1, date);
			Client[] data = (Client[]) q.execute();
			return data[0];			
		} catch (DatabaseException e) {
			// TODO Auto-generated catch block
			return null;
		} 
		
	}
	
	public static Client existsLodgingforBed(Integer idBed,Date date){
		GearsDataStore ds = (GearsDataStore) GWT.create(Client.class);
		try {
			GearsQuery q = ds.getNamedQuery(Client.EXISTS_LODGING_FOR_BED);
			q.setInteger(0, idBed);
			q.setDate(1, date);
			Client[] data = (Client[]) q.execute();
			return data[0];			
		} catch (DatabaseException e) {
			// TODO Auto-generated catch block
			return null;
		} 
		
	}

}
